/*
 * Copyright 2010 Dietrich Pfeifle
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.libriami.model;

import org.libriami.model.tools.compare.ApproxMatchable;
import org.libriami.model.tools.compare.StringCompare;

public class PhoneNumber implements ApproxMatchable {

	public enum Type {
		DEFAULT, HOME, WORK, CELL
	}

	private String number;
	private final Type type;

	public PhoneNumber(String number) {
		this.number = number;
		this.type = Type.DEFAULT;
	}

	public PhoneNumber(String number, Type type) {
		this.number = number;
		this.type = type;
	}

	public String getNumber() {
		return number;
	}

	public void setNumber(String number) {
		this.number = number;
	}

	public Type getType() {
		return type;
	}

	@Override
	public String toString() {
		return number;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((number == null) ? 0 : number.hashCode());
		result = prime * result + ((type == null) ? 0 : type.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		PhoneNumber other = (PhoneNumber) obj;
		if (number == null) {
			if (other.number != null)
				return false;
		} else if (!number.equals(other.number))
			return false;
		if (type != other.type)
			return false;
		return true;
	}

	@Override
	public double matchTo(ApproxMatchable o) {
		return StringCompare.compare(number, ((PhoneNumber) o).number);
	}

	@Override
	public void merge(ApproxMatchable other) {
		throw new IllegalArgumentException("NYI");
	}

}
